package fr.nts.application.novadmin.database.model.employe;

import java.util.Set;

import javax.persistence.CollectionTable;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.Table;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.collect.Sets;

import fr.nts.application.novadmin.database.model.employe.embedded.Conge;

/**
 * Represente un employé Novadmin avec ces infos complètes
 * 
 * @author sco
 * @version 1.0.0
 */
@Entity
@Table(name = "novadmin_employee")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class NovadminEmployeComplet extends BaseNovadminEmploye{
    
    private static final long serialVersionUID = 1L;
    
    private static final Logger log = LoggerFactory.getLogger(NovadminEmployeComplet.class);
    
    @ElementCollection(fetch = FetchType.EAGER)
    @CollectionTable(name = "novadmin_employe_conge", joinColumns = @JoinColumn(name = "employe_id"))
    private Set<Conge> conges = Sets.newHashSet();
    
    
    /*
     * (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString(){
    	if(getLog().isDebugEnabled()){
	    	return new ToStringBuilder(this).appendSuper(super.toString())
	    	                                .append("Nb conge", conges.size())
	                                        .toString();
    	}else{
    		return super.toString();
    	}
    }


    /*
     * (non-Javadoc)
     * @see fr.nts.framework.database.jpa.model.AJPAObject#getLog()
     */
    @Override
    protected Logger getLog(){
    	return log;
    }


    // GETTER / SETTER
	public Set<Conge> getConges(){
		return conges;
	}

	public void setConges(Set<Conge> conges){
		this.conges = conges;
	}
}